<#list domains as domain>
<manager>   
package ${coder.packageName}.manager.${domain.entityName?lower_case}; 
import java.util.List;

import ${coder.packageName}.domain.${domain.entityName?cap_first};

/**
 * 
 * @desc ${domain.desc}
 *
 */
public interface ${domain.entityName?cap_first}Manager {
	/**
	 * ��ѯ${domain.desc}
	 * @param query
	 * @return
	 */
	List<${domain.entityName?cap_first}> query(${domain.entityName?cap_first}Query query);
	/**
	 * ��ѯ${domain.desc}���ҳ��
	 * @param query
	 * @return
	 */
	Integer queryCount(${domain.entityName?cap_first}Query query);
	
	/**
	 * ����${domain.desc}
	 * @param 
	 */
	int update(${domain.entityName?cap_first} ${domain.entityName?cap_first});
	
	/**
	 * ���${domain.desc}
	 */
	void add(${domain.entityName?cap_first} ${domain.entityName});
	
	/**
	* ���id��ȡ${domain.desc}
	*/
	${domain.entityName?cap_first} findById(${domain.idProperty.type.type} ${domain.idProperty.name?uncap_first});
	
	<#list services as service>
	<#if domain == service.refDomain>	
	<#list service.methods as method>
	/**
	* ${method.desc}<#list method.parameters as para>
	* @param ${para.alias} ${para.alias}</#list>
	*/
	<#if method.returnList == true>List<${method.returnType}><#else>${method.returnType}</#if> ${method.name}(<#assign index=0/><#assign currentsize=method.parameters?size-1/><#list method.parameters as para>${para.property.type.type} ${para.alias?uncap_first}<#if index != currentsize >,</#if><#assign index=index+1/></#list>);	
	</#list>
	</#if>
	</#list>
}
</manager>
<managerimpl>
package ${coder.packageName}.manager.${domain.entityName?lower_case}.impl; 

import java.util.List;

import ${coder.packageName}.manager.BaseManager;

import ${coder.packageName}.manager.${domain.entityName?lower_case}.${domain.entityName?cap_first}Manager; 

import ${coder.packageName}.domain.${domain.entityName?lower_case}.${domain.entityName?cap_first};
import ${coder.packageName}.domain.${domain.entityName?lower_case}.${domain.entityName?cap_first}Query;
import ${coder.packageName}.dao.${domain.entityName?lower_case}.${domain.entityName?cap_first}Dao;
/**
 * 
 * @desc ${domain.desc}
 *
 */
public class ${domain.entityName?cap_first}ManagerImpl extends BaseManager implements ${domain.entityName?cap_first}Manager  {
	private ${domain.entityName?cap_first}Dao ${domain.entityName?uncap_first}Dao;
	/**
	 * ��ѯ${domain.desc}
	 * @param query
	 * @return
	 */
	public List<${domain.entityName?cap_first}> query(${domain.entityName?cap_first}Query query){
		return ${domain.entityName?uncap_first}Dao.query(query);
	}
	/**
	 * ��ѯ${domain.desc}���ҳ��
	 * @param query
	 * @return
	 */
	public Integer queryCount(${domain.entityName?cap_first}Query query){
		return ${domain.entityName?uncap_first}Dao.queryCount(query);
	}
	
	/**
	 * ����${domain.desc}
	 * @param 
	 */
	public int update(${domain.entityName?cap_first} ${domain.entityName?uncap_first}){
		return ${domain.entityName?uncap_first}Dao.update(${domain.entityName?uncap_first});
	}
	
	/**
	 * ���${domain.desc}
	 */
	public void add(${domain.entityName?cap_first} ${domain.entityName?uncap_first}){
		${domain.entityName?uncap_first}Dao.add(${domain.entityName?uncap_first});
	}
		
	/**
	 * ��������ȡ${domain.desc}
	 */
	public ${domain.entityName?cap_first} findById(${domain.idProperty.type.type} ${domain.idProperty.name?uncap_first}){		
		${domain.entityName?cap_first}Query query = new ${domain.entityName?cap_first}Query();
		query.set${domain.idProperty.name?cap_first}(${domain.idProperty.name?uncap_first});
		List<${domain.entityName?cap_first}> list = ${domain.entityName?uncap_first}Dao.query(query);
		if (list.size() == 1) {
			return list.get(0);
		}
		return null;
	}
	<#list services as service>
	<#if domain == service.refDomain>	
	<#list service.methods as method>
	
	/**
	* ${method.desc}<#list method.parameters as para>
	* @param ${para.alias} ${para.alias}</#list>
	*/
	public <#if method.returnList == true>List<${method.returnType}></#if><#if method.returnList == false>${method.returnType}</#if> ${method.name}(<#assign index=0/><#assign currentsize=method.parameters?size-1/><#list method.parameters as para>${para.property.type.type} ${para.alias?uncap_first}<#if index != currentsize >,</#if><#assign index=index+1/></#list>){		
		<#assign newSql=0/>
		<#list method.parameters as para><#if para.queryType != "equal"><#assign newSql=1/><#break/></#if></#list>		
		<#if newSql == 1>
		<#if method.paging == true>
		${domain.entityName?cap_first}Query query = new ${domain.entityName?cap_first}Query();
			<#list method.parameters as para>
			<#if para.alias?uncap_first!= "pageSize" && para.alias?uncap_first!= "pageIndex">
		query.set${para.alias?cap_first}(${para.alias?uncap_first});
			</#if>
			</#list>
		PaginatedList<${domain.entityName?cap_first}> list = new MysqlPaginatedArrayList<${domain.entityName?cap_first}>(pageIndex, pageSize);
		Integer count=${domain.entityName?uncap_first}Dao.${method.name}Count(query);
		list.setTotalItem(count);
		list.setStartRow(list.getStartRow());
		list.setEndRow(list.getEndRow());
		list.addAll(${domain.entityName?uncap_first}Dao.${method.name}(query);
		return list;		
		<#else>
		return ${domain.entityName?uncap_first}Dao.${method.name}(<#assign index=0/><#assign currentsize=method.parameters?size-1/><#list method.parameters as para>${para.alias?uncap_first}<#if index != currentsize >,</#if><#assign index=index+1/></#list>);
		</#if>
		<#else>
		${domain.entityName?cap_first}Query query = new ${domain.entityName?cap_first}Query();
		<#list method.parameters as para>
		<#if para.property.name?uncap_first!= "pageSize" && para.property.name?uncap_first!= "pageIndex">
		query.set${para.property.name?cap_first}(${para.property.name?uncap_first});
		</#if>
		</#list>	
		<#if method.paging == true>				
		PaginatedList<${domain.entityName?cap_first}> list = new MysqlPaginatedArrayList<${domain.entityName?cap_first}>(pageIndex, pageSize);
		list.setTotalItem(${method.name}Count(query));
		list.setStartRow(list.getStartRow());
		list.setEndRow(list.getEndRow());
		list.addAll(${domain.entityName?uncap_first}Dao.query(query));
		return list;
		<#else>
		List<${domain.entityName?cap_first}> list = ${domain.entityName?uncap_first}Dao.query(query);
		if (list.size() == 1) {
			return list.get(0);
		}
		</#if>
		</#if>
	}
	</#list>
	</#if>
	</#list>
	
	
	public void set${domain.entityName?cap_first}Dao(${domain.entityName?cap_first}Dao ${domain.entityName?uncap_first}Dao) {
		this.${domain.entityName?uncap_first}Dao = ${domain.entityName?uncap_first}Dao;
	}
}
</managerimpl>
</#list> 